package top.zhangjianyong.tools.utils;

import top.zhangjianyong.tools.entity.ETFData;

import java.math.RoundingMode;
import java.util.List;

/**
 * @author ： zhangjianyong
 * @date ： 2022/9/30 11:32 AM
 */
public class StringBuildUtil {

    private StringBuilder SB = new StringBuilder();

    public StringBuildUtil() {
        this.SB = new StringBuilder();
    }


    public void append(String source) {
        SB.append(source);
    }

    public void append(String source, String... obj) {
        for (String s : obj) {
            source = source.replaceFirst("\\{}", s);
        }
        append(source);

    }

    /**
     * @param list
     * @param flag true 打印预测
     */
    public void append(List<ETFData> list, boolean flag) {
        list.forEach(d -> {
            SB.append(d.getValueDate() == null ? "" : d.getValueDate().toString());
            SB.append("\t");
        });
        SB.append("\n");
        if (flag) {
            list.forEach(d -> {
                SB.append(d.getDailyRate().toString());
                SB.append("\t");
            });
        } else {
            list.forEach(d -> {
                SB.append(d.getAvgValue().setScale(4, RoundingMode.HALF_UP).toString());
                SB.append("\t");
            });
        }
        SB.append("\n");
    }

    public String getString() {
        if (SB == null) return "";
        return SB.toString();
    }
}
